package com.kchouse.union;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bm.library.Info;
import com.bm.library.PhotoView;
import com.kchouse.R;
import com.kchouse.common.BaseActivity;
import com.squareup.picasso.Picasso;

public class PhotoActivity extends BaseActivity implements View.OnClickListener{

    private PhotoActivity mContent;
    private TextView tv_title;
    private ImageView iv_back;
    private PhotoView pv_item;
    private Intent intent;
    private ImageView iv_item;
    private String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo);

        mContent = this;
        intiData();
        intiView();
    }

    private void intiData() {
       intent= getIntent();
       url = intent.getStringExtra("url");
    }

    private void intiView() {
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_title.setText("");
        iv_back = (ImageView) findViewById(R.id.iv_back);
        iv_back.setOnClickListener(this);

        intiPhotoView();
    }

    /**
     * 初始化PhotoView
     */
    private void intiPhotoView() {
        pv_item = (PhotoView) findViewById(R.id.pv_item);
        Picasso.with(mContent).load(url).error(R.mipmap.ic_loadingerror).into(pv_item);
        // 启用图片缩放功能
        pv_item.enable();
//// 禁用图片缩放功能 (默认为禁用，会跟普通的ImageView一样，缩放功能需手动调用enable()启用)
//        pv_item.disenable();
// 获取图片信息
        Info info = pv_item.getInfo();
// 从普通的ImageView中获取Info
//        Info info = pv_item.getImageViewInfo(iv_item);
//// 从一张图片信息变化到现在的图片，用于图片点击后放大浏览，具体使用可以参照demo的使用
        pv_item.animaFrom(info);
//// 从现在的图片变化到所给定的图片信息，用于图片放大后点击缩小到原来的位置，具体使用可以参照demo的使用
//        pv_item.animaTo(info,new Runnable() {
//            @Override
//            public void run() {
//                //动画完成监听
//            }
//        });
//// 获取/设置 动画持续时间
//        pv_item.setAnimaDuring(int during);
//        int d = pv_item.getAnimaDuring();
//// 获取/设置 最大缩放倍数
//        pv_item.setMaxScale(float maxScale);
//        float maxScale = pv_item.getMaxScale();
//// 设置动画的插入器
//        pv_item.setInterpolator(Interpolator interpolator);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.iv_back:
                finish();
                break;
        }
    }
}
